﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UControl_UClogin : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
            if (Session["userlogin"] == null)
            {
                Panel1.Visible = true;
                Panel2.Visible = false;
            }
            else if (Session["userlogin"] != null)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
                YqhData obj = new YqhData();
                string sql = string.Format("select uheadurl from userinfo where uname='{0}'", Session["userlogin"].ToString());
                DataSet ds = obj.FillDataSet(sql);
                string url = "../" + ds.Tables[0].Rows[0]["uheadurl"].ToString();
                imghead.ImageUrl = url;
                lbmane.Text = Session["userlogin"].ToString();
            }
   

    }
    protected void btnreg_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
    protected void btnok_Click(object sender, ImageClickEventArgs e)
    {
        YqhData obj = new YqhData();
        string str = string.Format(@"select Count(uname)
                from userinfo
                where uname = '{0}'
	                and uPwd = '{1}'
                    and upower = '0'",
                                txtname.Text,
                                txtpwd.Text);
        int i = Convert.ToInt32(obj.ExecuteScalar(str));
        if (txtyzm.Text.ToLower() == Session["yzm"].ToString().ToLower())
        {
            if (i >= 1)
            {
                Session["userlogin"] = txtname.Text;
                if (Session["newsurl"] != null)
                {
                    Response.Redirect(Session["newsurl"].ToString());
                }
                else if (Session["newsurl"] == null)
                {
                    //Response.Redirect("Index.aspx");
                    Response.Write("<script language=javascript>window.location.href=window.location.href;</script>");
                    //Response.AddHeader("Refresh", "0"); 

                }
            }
            else
            {
                Label1.Text = obj.Msg("登录代码或密码错误,请重新输入！");
            }
        }
        else
        {
            Label1.Text = obj.Msg("验证码错误");
        }
    }

}
